package com.gitee.zycra.union.api.common.param;

import com.gitee.zycra.union.api.common.model.ApiInterface;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class UpdateInterfaceParam {

    /**
     * 接口ID
     */
    @NotNull(message = "接口ID不能为空")
    private Long id;

    /**
     * 接口名称
     */
    @NotNull(message = "接口名称不能为空")
    private String interfaceName;

    /**
     * 请求类型
     *
     * @see com.gitee.zycra.union.api.common.enums.InterfaceMethodEnum
     */
    @NotNull(message = "请求类型不能为空")
    private Long interfaceMethod;

    /**
     * 接口路径
     */
    @NotNull(message = "接口路径不能为空")
    private String interfaceUri;

    /**
     * 接口状态
     *
     * @see com.gitee.zycra.union.api.common.enums.InterfaceStatusEnum
     */
    @NotNull(message = "接口状态不能为空")
    private Integer interfaceStatus;

    /**
     * 所在目录ID
     */
    @NotNull(message = "目录ID不能为空")
    private Long interfaceFolderId;

    /**
     * 入参类型
     *
     * @see com.gitee.zycra.union.api.common.enums.RequestParamTypeEnum
     */
    @NotNull(message = "入参类型不能为空")
    private Integer requestParamType;

    /**
     * 入参配置
     */
    @NotNull(message = "入参配置不能为空")
    private String requestParam;

    /**
     * 出参配置
     */
    @NotNull(message = "出参配置不能为空")
    private String responseParam;

    /**
     * 成功返回值示例
     */
    @NotNull(message = "成功返回值示例不能为空")
    private String successResponseValue;

    /**
     * 失败返回值示例
     */
    private String failResponseValue;

    public static ApiInterface convertToApiInterface(UpdateInterfaceParam updateInterfaceParam) {
        if (updateInterfaceParam == null) {
            return null;
        }
        return new ApiInterface()
                .setId(updateInterfaceParam.getId())
                .setInterfaceName(updateInterfaceParam.getInterfaceName())
                .setInterfaceMethod(updateInterfaceParam.getInterfaceMethod())
                .setInterfaceUri(updateInterfaceParam.getInterfaceUri())
                .setInterfaceStatus(updateInterfaceParam.getInterfaceStatus())
                .setInterfaceFolderId(updateInterfaceParam.getInterfaceFolderId())
                .setRequestParamType(updateInterfaceParam.getRequestParamType())
                .setRequestParam(updateInterfaceParam.getRequestParam())
                .setResponseParam(updateInterfaceParam.getResponseParam())
                .setSuccessResponseValue(updateInterfaceParam.getSuccessResponseValue())
                .setFailResponseValue(updateInterfaceParam.getFailResponseValue());
    }
}
